import { RegisterUser } from "../pages/Register";
import { UpdatePassword } from "../pages/UpdatePassword";
import axiosInstance from "./http";

export interface User {
  id: string;
  username: string;
  nickName: string;
  email: string;
  headPic: string;
  createTime: string;
}

export interface LoginRes {
  token: string;
  user: object;
  message: string;
}

export interface RegisterCaptchaRes {
  success: boolean;
  message: string;
}

export interface UpdatePasswordCaptchaRes extends RegisterCaptchaRes {}

export interface RegisterRes {
  success: boolean;
  message: string;
  user: User;
}

export const login = (username: string, password: string) => {
  return axiosInstance.post<LoginRes>("/user/login", {
    username,
    password,
  });
};

export const registerCaptcha = (email: string) => {
  return axiosInstance.post<RegisterCaptchaRes>("/user/register-captcha", {
    email,
  });
};

export const register = (registerUser: RegisterUser) => {
  return axiosInstance.post<RegisterRes>("/user/register", registerUser);
};

export const updatePasswordCaptcha = (email: string) => {
  return axiosInstance.post<UpdatePasswordCaptchaRes>(
    "/user/update_password/captcha",
    {
      email,
    }
  );
};

// export async function updatePassword(data: UpdatePassword) {
export const updatePassword = (data: UpdatePassword) => {
  return axiosInstance.post("/user/update_password", data);
};
